package com.example.administrator.testpersionn;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ViewTestActivity extends AppCompatActivity {

    @BindView(R.id.tilText)
    TextInputLayout tilText;
    @BindView(R.id.mSwitchCompat)
    SwitchCompat mSwitchCompat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_test);
        ButterKnife.bind(this);
        tilText.setError("超出字数限制");
        initView();

    }

    private void initView() {
        mSwitchCompat.setTextOff("开");     //设置关闭时的文字
        mSwitchCompat.setTextOn("关");       //设置打开时的文字
        mSwitchCompat.setShowText(true);     //设置是否显示文字
        mSwitchCompat.setSwitchPadding(20);  //设置文字与开关的间隙
        mSwitchCompat.setChecked(true);      //设置是否是选中(打开)状态
        mSwitchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(com.example.administrator.out1.ViewTestActivity.this);
                bottomSheetDialog.setCanceledOnTouchOutside(true);
                TextView textView = new TextView(com.example.administrator.out1.ViewTestActivity.this);
                textView.setText("反反复复");

                bottomSheetDialog.setContentView(textView);
                bottomSheetDialog.show();
            }
        });  //设置打开关闭监听

    }

    public void toastSnarkBar(View view) {
        Snackbar.make(view, "哈哈哈哈", Snackbar.LENGTH_LONG).setAction("退出", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(com.example.administrator.out1.ViewTestActivity.this, "取消按钮", Toast.LENGTH_SHORT).show();
            }
        }).setActionTextColor(Color.RED).show();
    }
}
